package com.hsw.habit.model;

import java.util.HashMap;
import java.util.Map;

public class JsonData {

    private Status status;
    private Object data;

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static JsonData error() {
        return error(4001);
    }

    public static JsonData error(int code) {
        return error(code,"发生了错误");
    }

    public static JsonData error(int code, String message) {
        JsonData result = new JsonData();
        result.data = null;
        result.status = new Status(code,message);
        return result;
    }

    public static JsonData success() {
        return success(null);
    }

    public static JsonData success(Object object) {
        JsonData result = new JsonData();
        result.data = object;
        result.status = new Status(1001,"success");
        return result;
    }

    private static class Status {
        int code;
        String msg;

        public Status(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public int getCode() {
            return code;
        }

        public void setCode(int code) {
            this.code = code;
        }

        public String getMsg() {
            return msg;
        }

        public void setMsg(String msg) {
            this.msg = msg;
        }

        @Override
        public String toString() {
            return "Status{" +
                    "code=" + code +
                    ", msg='" + msg + '\'' +
                    '}';
        }
    }

}

